package ExerciseOne;

public class CheckAccount extends Account{
	
	private double overdraft;//可透支额度
	
	public CheckAccount()
	{
		
	}
	
	public CheckAccount(int id,double balance,double annualInterestRate, double overdraft)
	{
		super(id, balance, annualInterestRate);//调用的是父类的构造器
		this.overdraft = overdraft;
	}
	
	public double getOverdraft() {
		return overdraft;
	}

	public void setOverdraft(double overdraft) {
		this.overdraft = overdraft;
	}

	@Override//取钱方法
	public void withdraw(double amount) {
		
		if(amount < getBalance())//余额足够，直接取钱
		{
			super.withdraw(amount);
		}
		else if(overdraft >= amount - getBalance())
		{
			overdraft-=(amount-getBalance());
			setBalance(0);
		}
		else
		{
			System.out.println("超过透支额度");
		}
	}
}
